package chixing.day19.work;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Test {
    public static void main(String[] args) {
        User user = new User(1, false, true);
        Product product = new Product(1, "Product 1", 200.0, false);
        Product product2 = new Product(2, "Product 2", 300.0, true);
        List<Product> products = new ArrayList<>();
        products.add(product);
        products.add(product2);

        // 计算订单原始总价
        double originalTotalPrice = 0;
        for (Product p : products) {
            originalTotalPrice += p.getPrice();
        }

        Order order = new Order(user, products, originalTotalPrice);

        DiscountStrategy discountStrategy1 = new NewUserDiscount();
        DiscountStrategy discountStrategy2 = new VIPDiscount();
        DiscountStrategy discountStrategy3 = new FestivalDiscount();

        Set<DiscountStrategy> discountStrategies = new HashSet<>();
        discountStrategies.add(discountStrategy1);
        discountStrategies.add(discountStrategy2);
        discountStrategies.add(discountStrategy3);

        System.out.println("订单原始价格：" + order.getOriginalTotalPrice());

        double totalDiscountedPrice = 0;
        for (Product p : products) {
            double productPrice = p.getPrice();
            double discountedPrice = productPrice;

            if (user.isNewUser() && discountStrategies.contains(discountStrategy1)) {
                discountedPrice = discountStrategy1.applyDiscount(discountedPrice, user, p);
                System.out.println(p.getProductName() + " 新用户折扣后价格：" + discountedPrice);
                user.setNewUser(false);
            }
            if (user.isVip() && discountStrategies.contains(discountStrategy2)) {
                discountedPrice = discountStrategy2.applyDiscount(discountedPrice, user, p);
                System.out.println(p.getProductName() + " VIP折扣后价格：" + discountedPrice);
            }
            if (p.isAttend() && discountStrategies.contains(discountStrategy3)) {
                discountedPrice = discountStrategy3.applyDiscount(discountedPrice, user, p);
                System.out.println(p.getProductName() + " 节日折扣后价格：" + discountedPrice);
            }

            totalDiscountedPrice += discountedPrice;
            System.out.println(p.getProductName() + " 最终价格：" + discountedPrice);
        }

        order.setOriginalTotalPrice(totalDiscountedPrice);
        System.out.println("订单实际价格：" + order.getOriginalTotalPrice());
    }
}
